Skip to content

Conversation

@gunpal5
Copy link
Collaborator

@gunpal5 gunpal5 commented Mar 12, 2025

Fixed MeaiFunction tool was ignoring primitive data types arguments

Refactor and simplified Json Schema generation codes.

Summary by CodeRabbit

  • New Features
    • Introduced a new project entry for "CSharpToJsonSchema.MeaiTests" in the solution.
  • Refactor
    • Removed the Descriptions property from MethodData, altering the structure of method data processing.
    • Enhanced handling of JsonElement types in the GetArgsString method.
    • Restructured schema conversion logic, improving attribute handling and error management.
  • Tests
    • Added assertions in tests to validate properties of OpenApiSchema related to tools.
    • Cleaned up obsolete snapshots and auto-generated test artifacts to improve code clarity and maintainability.

Gunpal Jain and others added 22 commits March 9, 2025 09:47
…emaAttribute.cs and FunctionToolAttribute.cs
# Conflicts:
#	src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs
Replaced direct dictionary access with TryGetValue to prevent potential KeyNotFound exceptions. This ensures safer and more robust handling of missing keys when fetching "mainFunction_Desc".
Removed unnecessary try-catch block around async call invocation and adjusted formatting for better code clarity. Minor whitespace and indentation improvements were also made to enhance consistency and maintainability.
Added detailed XML documentation for MeaiFunction class and its members, improving code readability and maintainability. Introduced support for strict mode and updated method implementations to enhance functionality. These changes provide better structure and guidance for future development.
Replaced GenericFunctionTool with GoogleFunctionTool to align with the updated namespace and class structure. This ensures compatibility with the latest library changes and maintains consistency in functionality.
# Conflicts:
#	CSharpToJsonSchema.sln
#	src/libs/CSharpToJsonSchema/MeaiFunction.cs
Generated snapshot files for ToolsJsonSerializerContext to support integration tests for various tool methods and their serialization. This includes handling for different types of arguments like string, void, and async inputs.
The `MethodFunction` test method is commented out, likely due to being unused or obsolete. This change improves code clarity by removing an inactive test without deleting it entirely, preserving it for potential future use.
# Conflicts:
#	CSharpToJsonSchema.sln
#	src/tests/AotConsole/Services/StudentRecordService.cs
refactor: Simplified JsonSchema generation codes
@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2025

Walkthrough

This pull request adds a new project to the solution and updates the core JSON schema conversion logic while streamlining test infrastructure. In the main libraries, the changes remove the use of the parameter descriptions in the conversion flow, update initialization of method descriptions, and add a new conditional branch for handling extra JSON element types. The schema conversion method now accepts a different signature and uses helper methods for description extraction and type fixing. In addition, a large number of auto-generated snapshot and JSON serialization files have been removed from the tests.

Changes

File(s) Change Summary
CSharpToJsonSchema.sln New project "CSharpToJsonSchema.MeaiTests" with GUID {DC07C90E-A58C-44B3-82D2-E2EB8F777B92} added to solution configuration.
src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs
src/libs/CSharpToJsonSchema.Generators/Models/MethodData.cs
Removed Descriptions property/field from MethodData instances and record struct, omitting parameter description data.
src/libs/CSharpToJsonSchema.Generators/Sources.Tools.cs Updated initialization of methodDescriptions to create a new dictionary and add a fixed "MainFunction_Desc" entry.
src/libs/CSharpToJsonSchema/MeaiFunction.cs Added a new else branch in GetArgsString to handle non-array/object JsonElement by assigning a JsonValue.
src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs Refactored schema conversion: removed ConvertToCompatibleSchemaSubset, modified ConvertToSchema signature, and introduced ExtractDescription and FixType methods.
src/tests/AotConsole/Program.cs Commented out a line assigning a prompt, with no functional impact on the active code.
src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs Added assertions to validate the properties of an OpenApiSchema for a tool and cleaned up extraneous whitespace.
Multiple Snapshot Files (in src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/) Removed numerous auto-generated JSON serialization metadata files related to various tools (e.g. IVariousTypesTools, IWeatherTools, IWeatherStrictTools) and diagnostic snapshots containing empty JSON arrays.
src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.received.cs Updated the GeneratedCodeAttribute version from "3.0.0.0" to "0.0.0.0".

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant SB as SchemaBuilder
    participant ED as ExtractDescription
    participant FT as FixType

    C->>SB: Call ConvertToSchema(JsonTypeInfo, descriptionString)
    SB->>SB: Invoke GetJsonSchemaAsNode
    SB->>ED: Call ExtractDescription(context, schema, dics)
    ED-->>SB: Return updated schema node
    SB->>FT: Call FixType(schema)
    FT-->>SB: Return fixed schema node
    SB-->>C: Return OpenApiSchema
Loading
sequenceDiagram
    participant M as MeaiFunction
    participant JE as JsonElement

    M->>M: Evaluate args.Value type
    alt JsonElement is array or object
        M->>M: Process using existing branches
    else
        M->>M: Create JsonValue using JsonValue.Create(element)
        M->>M: Assign value to jsonObject[args.Key]
    end
Loading

Poem

Oh, what a day for a rabbit so keen,
I hopped through code where changes are seen.
No more excess descriptions to weigh,
Snapshots and serializers now gone away.
With schema refined and logic so neat,
I bounce with joy on this coding treat!
🥕🐇 Happy hops and clever tweaks!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ gunpal5
❌ Gunpal Jain


Gunpal Jain seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
CSharpToJsonSchema.sln (1)

85-87: ⚠️ Potential issue

Configuration issue in the solution file

The pipeline is reporting warnings about missing Release configuration for the new projects.

{DC07C90E-A58C-44B3-82D2-E2EB8F777B92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DC07C90E-A58C-44B3-82D2-E2EB8F777B92}.Debug|Any CPU.Build.0 = Debug|Any CPU
+{DC07C90E-A58C-44B3-82D2-E2EB8F777B92}.Release|Any CPU.ActiveCfg = Release|Any CPU
+{DC07C90E-A58C-44B3-82D2-E2EB8F777B92}.Release|Any CPU.Build.0 = Release|Any CPU
+{1942E3E5-F151-4C90-BECE-140AAD8C66DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
+{1942E3E5-F151-4C90-BECE-140AAD8C66DE}.Release|Any CPU.Build.0 = Release|Any CPU
🧹 Nitpick comments (7)
src/libs/CSharpToJsonSchema/MeaiFunction.cs (1)

94-96: Empty block for JsonNode handling

The code has an empty block for handling JsonNode arguments which could potentially be improved.

Consider implementing proper handling for JsonNode arguments instead of leaving an empty block:

else if (args.Value is JsonNode node)
{
+    jsonObject[args.Key] = node;
}
src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs (2)

130-132: Remove duplicate test for tool.Description.

Lines 131 and 135 both assert tool.Description.Should().Be("Get student record for the year");. Repeating the same assertion is redundant unless there's a very specific reason to validate the same condition twice.

 130         Tool tool = tools[0];
-131         tool.Description.Should().Be("Get student record for the year");
 132

134-138: Refinement suggestion for improved readability.

The lines here add clarity to retrieving and casting tool.Parameters to an OpenApiSchema. The usage looks valid; however, consider grouping the schema reference and its asserts together for readability. For instance:

  1. Take note that line 135 is a duplication of line 131.
  2. Put the object creation/cast immediately above or below the tool assert lines to keep test arrangements clear.
src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs (4)

20-36: Simplify return statements in TransformSchemaNode.

Currently, lines 32-35 always return schema whether context.PropertyInfo is null or not. You could move the return schema; outside the if block to remove repetition, making the code more concise.

+                TransformSchemaNode = (context, schema) =>
                 {
                     if (context.TypeInfo.Type.IsEnum)
                     {
                         schema["type"] = "string";
                     }
-                    if (context.PropertyInfo == null)
-                        return schema;

                     ExtractDescription(context, schema, dics);

-                    return schema;
+                    return schema;
                 },

40-44: Validate assumption that all properties are required.

Auto-adding all properties to required might be too broad if your JSON schema is meant to allow optional fields. Clarify whether this is intended behavior or consider differentiating required vs. optional.


45-45: Replace Magic String “mainFunction_Desc”.

Using “mainFunction_Desc” inline might be fragile. Consider introducing a well-named constant or providing an explanatory comment so future maintainers understand why “mainFunction_Desc” is special.


99-125: Fix typo in error message and verify type array safety.

  1. Typo: “strucutured” should be “structured” in the message describing Google’s API requirement.
  2. Consider gracefully handling cases when array elements are not strings, or containing unexpected data types, rather than unconditionally calling GetValue<string>().
-                        $"Google's API for strucutured output requires every property to have one defined type, ...
+                        $"Google's API for structured output requires every property to have one defined type, ...
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e538485 and 8c68191.

📒 Files selected for processing (50)
  • CSharpToJsonSchema.sln (1 hunks)
  • src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs (0 hunks)
  • src/libs/CSharpToJsonSchema.Generators/Models/MethodData.cs (0 hunks)
  • src/libs/CSharpToJsonSchema.Generators/Sources.Tools.cs (1 hunks)
  • src/libs/CSharpToJsonSchema/MeaiFunction.cs (1 hunks)
  • src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs (2 hunks)
  • src/tests/AotConsole/Program.cs (1 hunks)
  • src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs (1 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Boolean.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateOnly.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateTime.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Double.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetCurrentWeather3Args.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetJsonTypeInfo.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int32.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int64.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.PropertyNames.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Single.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes_Diagnostics.verified.txt (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Calls.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Double.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherAsyncArgs.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetJsonTypeInfo.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.PropertyNames.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.String.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Tools.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Unit.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Weather.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Calls.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Double.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeather2Args.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeatherAsync2Args.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetJsonTypeInfo.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.PropertyNames.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.String.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Tools.generated.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Unit2.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Weather2.g.verified.cs (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.received.cs (1 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict_Diagnostics.verified.txt (0 hunks)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather_Diagnostics.verified.txt (0 hunks)
💤 Files with no reviewable changes (43)
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes_Diagnostics.verified.txt
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.PropertyNames.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather_Diagnostics.verified.txt
  • src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetJsonTypeInfo.g.verified.cs
  • src/libs/CSharpToJsonSchema.Generators/Models/MethodData.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Boolean.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict_Diagnostics.verified.txt
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetJsonTypeInfo.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Unit2.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.PropertyNames.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetJsonTypeInfo.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Unit.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Tools.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.PropertyNames.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Tools.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Weather.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Tools.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Double.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Double.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateOnly.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Double.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Weather2.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int32.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Single.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.SetValueAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.Calls.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Int64.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.DateTime.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeatherAsync2Args.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.String.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.Calls.generated.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.String.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.Weather#IWeatherTools.GetCurrentWeatherAsyncArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.GetCurrentWeather2Args.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetValueArgs.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.GetCurrentWeather3Args.g.verified.cs
  • src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.VariousTypes#IVariousTypesTools.Calls.generated.verified.cs
🧰 Additional context used
🪛 GitHub Actions: Test
CSharpToJsonSchema.sln

[warning] 1-1: The project configuration for project 'CSharpToJsonSchema.MeaiTests' was not specified in the solution file for the solution configuration 'Release|Any CPU'.


[warning] 1-1: The project configuration for project 'AotConsole' was not specified in the solution file for the solution configuration 'Release|Any CPU'.

🔇 Additional comments (11)
src/tests/CSharpToJsonSchema.SnapshotTests/Snapshots/ToolTests.WeatherStrict#IWeatherStrictTools.g.received.cs (1)

12-12: Note on Version Number Update in GeneratedCode Attribute
The version number in the GeneratedCodeAttribute has been updated from "3.0.0.0" to "0.0.0.0". This change appears to be part of the restructuring effort. Please verify that this new version metadata is intentional and consistent with your generator’s versioning scheme, ensuring that any tooling or consumers relying on this metadata will not be negatively impacted.

src/libs/CSharpToJsonSchema.Generators/Sources.Tools.cs (1)

100-101: Refactored method description initialization approach

This change simplifies the description handling by using a single description value instead of relying on a collection of descriptions. This aligns with the removal of the Descriptions property from the MethodData record struct as mentioned in the AI summary.

src/tests/AotConsole/Program.cs (1)

12-12: Commented out unnecessary test prompt

Removing this specific test prompt cleans up the code while maintaining the primary functionality for testing with the student record prompt.

CSharpToJsonSchema.sln (1)

45-46: Added new MeaiTests project to the solution

The addition of this specialized test project is appropriate for validating the changes to the MeaiFunction implementation.

src/libs/CSharpToJsonSchema/MeaiFunction.cs (1)

91-92: Fixed handling of primitive JSON types

This change addresses the core issue mentioned in the PR title. Previously, the MeaiFunction was ignoring primitive data types in arguments because it only handled arrays and objects. Adding this else branch ensures that all primitive types (strings, numbers, booleans, etc.) are properly converted to JsonValue objects.

The implementation is correct as it uses JsonValue.Create() which handles all primitive JSON types appropriately.

src/tests/CSharpToJsonSchema.AotTests/JsonSerializationTests.cs (5)

139-141: No issues detected.

Validating the fullName property as a string with a descriptive text is appropriate. Looks good as written.


142-146: Proper schema validation for gradeFilters.

Ensures the property is declared as an array of strings with an appropriate description. Logic and naming are consistent with best practices for JSON-based schemas.


147-151: Correct usage of date-time format.

Declaring a property type as "string" with "date-time" format makes sense for enrollmentStartDate and the description is well-specified.


152-156: Consistent date-time schema approach.

This mirrors the logic above for enrollmentEndDate, ensuring the same type and format usage. Implementation is coherent.


157-159: Descriptive boolean field.

Marking isActive as a boolean and providing a clear description is aligned with JSON schema standards. No issues found.

src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs (1)

13-14: Consider handling null or invalid descriptionString.

JsonSerializer.Deserialize call on line 17 may throw an exception if descriptionString is null or invalid JSON. Ensure upstream callers or this method itself gracefully handles those edge cases.

Comment on lines +55 to +97
private static void ExtractDescription(JsonSchemaExporterContext context, JsonNode schema, IDictionary<string, string> dics)
{
// Determine if a type or property and extract the relevant attribute provider.
ICustomAttributeProvider? attributeProvider = context.PropertyInfo is not null
? context.PropertyInfo.AttributeProvider
: context.TypeInfo.Type;

// Look up any description attributes.
DescriptionAttribute? descriptionAttr = attributeProvider?
.GetCustomAttributes(inherit: true)
.Select(attr => attr as DescriptionAttribute)
.FirstOrDefault(attr => attr is not null);

var description = descriptionAttr?.Description;
if (string.IsNullOrEmpty(description))
{
if (context.PropertyInfo is null)
{
var propertyName = ToCamelCase(context.TypeInfo.Type.Name);
dics.TryGetValue(propertyName, out description);
}
}

FixType(schema);

// Apply description attribute to the generated schema.
if (description is not null)
{
if (schema is not JsonObject jObj)
{
// Handle the case where the schema is a Boolean.
JsonValueKind valueKind = schema.GetValueKind();

schema = jObj = new JsonObject();
if (valueKind is JsonValueKind.False)
{
jObj.Add("not", true);
}
}

jObj.Insert(0, "description", description);
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Check for possible null references when handling schema objects.

Inside ExtractDescription, if schema is unexpectedly null or not a JsonObject, lines 85–90 do some transformations but assume schema can always be re-cast to JsonObject. Consider explicitly verifying or throwing an exception earlier if schema is null.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs (1)

115-117: Inconsistent API reference in error messages.

The error messages still reference "LLM's API" while the AI summary suggested changing to "Google's API". Consider updating these error messages for consistency.

- $"LLM's API for strucutured output requires every property to have one defined type, not multiple options. Path: {schema.GetPath()} Schema: {schema.ToJsonString()}");
+ $"Google's API for structured output requires every property to have one defined type, not multiple options. Path: {schema.GetPath()} Schema: {schema.ToJsonString()}");

Also note the typo "strucutured" which should be "structured".

Also applies to: 121-123

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c68191 and b9e53e0.

📒 Files selected for processing (2)
  • src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs (0 hunks)
  • src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs (2 hunks)
💤 Files with no reviewable changes (1)
  • src/libs/CSharpToJsonSchema.Generators/Conversion/ToModels.cs
🔇 Additional comments (5)
src/libs/CSharpToJsonSchema/SchemaSubsetHelper.cs (5)

12-53: Updated schema conversion approach improves type handling.

The revised ConvertToSchema method now directly uses GetJsonSchemaAsNode with a custom transformation function, which simplifies the code flow. The schema transformation is now broken into smaller, more focused operations that seem to better handle various type scenarios.


20-36: Simplified schema node transformation.

The transformation process has been refactored to separate concerns. Enum handling converts enums to strings, and description extraction has been moved to a dedicated method. This separation of concerns makes the code more maintainable.


55-97: Improved description extraction and null handling.

The new ExtractDescription method properly addresses the previous review comment by explicitly handling the case where the schema is not a JsonObject. The code now properly transforms boolean schemas to objects before adding the description property.


83-93: Null-safe handling of schema objects.

This section properly addresses the previous review comment about null references when handling schema objects. The code now correctly handles the case where the schema is a boolean value rather than an object by creating a new JsonObject and setting appropriate values.


99-125: FixType method addresses the primitive type handling issue.

This new method appears to be the key implementation for fixing the MeaiFunction primitive data types issue mentioned in the PR objectives. It properly handles cases where "type" is an array (which can occur with nullable types or union types) and collapses it to a single type with nullable flag when appropriate.

@HavenDV HavenDV merged commit 6b36c90 into tryAGI:main Mar 12, 2025
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants